<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="项目编号" prop="projectCode">
        <el-input
          v-model="queryParams.projectCode"
          placeholder="请输入项目编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目名称" prop="projectName">
        <el-input
          v-model="queryParams.projectName"
          placeholder="请输入项目名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目部门" prop="projectDeptId">
        <treeselect v-model="queryParams.projectDeptId" :options="deptList" :show-count="true" placeholder="请选择归属部门" style="width: 200px"/>
      </el-form-item>
      <el-form-item label="资质主体" prop="projectAgencyId">
        <el-select v-model="queryParams.projectAgencyId"  clearable placeholder="请选择" >
          <el-option
            v-for="item in projectagencyList"
            :key="item.id"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="负责人" prop="projectLeader">
        <el-input
          v-model="queryParams.projectLeader"
          placeholder="请输入项目负责人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="项目经理" prop="projectDeveloper">
        <el-input
          v-model="queryParams.projectDeveloper"
          placeholder="请输入项目负责人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="中标单位" prop="projectWinBidder">
        <el-input
          v-model="queryParams.projectWinBidder"
          placeholder="请输入项目负责人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="招标类型" prop="projectTypeId">
        <el-select v-model="queryParams.projectTypeId" clearable placeholder="请选择">
          <el-option
            v-for="item in projecttypeList"
            :key="item.id"
            :label="item.text"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="招标方式" prop="projectTenderModeId">
        <el-select v-model="queryParams.projectTenderModeId" clearable placeholder="请选择">
          <el-option
            v-for="item in projecttendermodeList"
            :key="item.id"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="项目流程" prop="projectBidevaluationProcessId">
        <el-select v-model="queryParams.projectBidevaluationProcessId" clearable placeholder="请选择">
          <el-option
            v-for="item in projectbidevaluationprocessList"
              :key="item.id"
              :label="item.text"
              :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="付款方" prop="projectPayerId">
        <el-select v-model="queryParams.projectPayerId" clearable placeholder="请选择">
          <el-option
            v-for="item in projectpayerList"
            :key="item.id"
            :label="item.text"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="收费类型" prop="projectPaymentTypeId">
        <el-select v-model="queryParams.projectPaymentTypeId"  clearable placeholder="请选择" >
          <el-option
            v-for="item in projectPaymentTypeList"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="资金来源" prop="projectFundingSourceId">
        <el-select v-model="queryParams.projectFundingSourceId"  clearable placeholder="请选择" >
          <el-option
            v-for="item in projectfundingsourceList"
            :key="item.id"
            :label="item.text"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="立项时间" prop="createDateRange">
        <el-date-picker
          v-model="createDateRange"
          style="width: 240px"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="['00:00:00', '23:59:59']"
        ></el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:project:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:project:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:project:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:project:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-upload"
          size="mini"
          @click="openImportTable"
          v-hasPermi="['system:project:import']"
        >导入</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="projectList" @selection-change="handleSelectionChange">
      <el-table-column type="selection"  align="center" />
      <el-table-column label="ID" width="40" align="center" prop="id" />
      <el-table-column label="项目名称" align="left" width="160" prop="projectName" />
      <el-table-column label="项目编号" align="left" width="160" prop="projectCode" />
      <el-table-column label="类型方式" align="center" prop="projectTypeName" />
      <el-table-column label="项目流程" align="left" width="200" prop="projectBidevaluationProcessName" />
      <el-table-column label="预算(万)" align="center"  >
        <template slot-scope="scope" >
          {{scope.row.projectBudget/10000}}
        </template>
      </el-table-column>
      <el-table-column label="开标时间" align="left" width="150" prop="projectBidOpenTime" />
      <!--el-table-column label="审批状态" align="center">
        <template slot-scope="scope" >
          <div v-if="scope.row.approvalStatus === 1">已审核</div>
          <div v-else >未审核</div>
        </template>
      </el-table-column -->
      <el-table-column label="所属部门" align="center" prop="projectDeptName" />
      <el-table-column label="委托单位" align="left" width="200" prop="projectTenderee" />
      <el-table-column label="中标单位" align="left" width="200" prop="projectWinBidder" />
      <el-table-column label="资质主体" align="left" width="200" prop="projectAgencyName" />
      <!-- el-table-column label="项目状态" align="center" >
        <template slot-scope="scope" >
          <div v-if="scope.row.projectStatus === 1">正常</div>
          <div v-else >取消</div>
        </template>
      </el-table-column -->

      <el-table-column label="操作" fixed="right" width="120" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:project:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:project:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>




    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改项目管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="80%"  append-to-body>
      <el-dialog
        width="70%"
        :title="formInnerTitle"
        :visible.sync="formInnerVisible"
        append-to-body>

        <Tenderer v-if="formInnerType  === 'projectTenderee'" :getTendererRow="getProjectTendereeRow" />
        <User v-if="formInnerType  === 'projectDeveloper'" :get-row="getProjectDeveloperRow" />
        <User v-if="formInnerType  === 'projectOperator'" :get-row="getProjectOperatorRow" />
        <User v-if="formInnerType  === 'projectLeader'" :get-row="getProjectLeaderRow" />

      </el-dialog>


      <el-form ref="form" :model="form" :rules="rules" label-width="150px"  style="max-height: 400px; overflow-y: scroll;">
        <el-row>
          <el-col :span="12"  style="width: 910px">
            <el-form-item  label="项目名称" prop="projectName">
              <el-input v-model="form.projectName" placeholder="请输入项目名称"  />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
            <el-col :span="12">
              <el-form-item label="项目编号" prop="projectCode">

                <el-radio-group v-if="form.id == null"  v-model="form.isProjectCode">
                  <el-radio
                    v-for="dict in projectCodeSelectList"
                    :key="dict.value"
                    :label="dict.value"
                  >{{dict.label}}</el-radio>
                </el-radio-group>

                <el-input v-if="form.isProjectCode == 1 && form.id == null" v-model="form.projectCode" placeholder="请输入自行编号" style="width: 280px"/>
                <template v-if="form.id != null ">
                  <el-input  v-model="form.projectCode" placeholder="请输入编号" style="width: 280px"/>
                </template>
              </el-form-item>

            </el-col>
            <el-col :span="12">
              <el-form-item label="外部编号" prop="projectExternaltCode">
                <el-input v-model="form.projectExternaltCode" placeholder="请输入项目外部编号" style="width: 280px"/>
              </el-form-item>
            </el-col>
        </el-row>

        <el-row>
            <el-col :span="12">
              <el-form-item label="招标类型" prop="projectTypeId">
                <el-select v-model="form.projectTypeId" @change="selectProjectType" clearable placeholder="请选择" style="width: 280px">
                  <el-option
                    v-for="item in projecttypeList"
                    :key="item.id"
                    :label="item.text"
                    :value="item.id">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="招标方式" prop="projectTenderModeId">
                <el-select v-model="form.projectTenderModeId" @change="selectProjectTenderMode" clearable placeholder="请选择" style="width: 280px">
                  <el-option
                    v-for="item in projecttendermodeList"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
        </el-row>

        <el-row>
            <el-col :span="12">
              <el-form-item label="项目流程" prop="projectBidevaluationProcessId">
                <el-select v-model="form.projectBidevaluationProcessId" @change="selectProjectBidevaluationProcess" clearable placeholder="请选择" style="width: 280px">
                  <el-option
                    v-for="item in projectbidevaluationprocessList"
                    :key="item.id"
                    :label="item.text"
                    :value="item.id">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="评标方法" prop="projectBidevaluationModeId">
                <el-select v-model="form.projectBidevaluationModeId" @change="selectProjectBidevaluationMode" clearable placeholder="请选择" style="width: 280px">
                  <el-option
                    v-for="item in projectbidevaluationmodeList"
                    :key="item.id"
                    :label="item.text"
                    :value="item.id">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
        </el-row>

        <el-row>
            <el-col :span="12">
              <el-form-item label="资金来源" prop="projectFundingSourceId">
                <el-select v-model="form.projectFundingSourceId" @change="selectProjectFundingSource" clearable placeholder="请选择" style="width: 280px">
                  <el-option
                    v-for="item in projectfundingsourceList"
                    :key="item.id"
                    :label="item.text"
                    :value="item.id">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="服务费付款方" prop="projectPayerId">
                <el-select v-model="form.projectPayerId" @change="selectProjectPayer" clearable placeholder="请选择" style="width: 280px">
                  <el-option
                    v-for="item in projectpayerList"
                    :key="item.id"
                    :label="item.text"
                    :value="item.id">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="项目预算" prop="projectBudget">
              <el-input v-model="form.projectBudget" placeholder="请输入项目预算" style="width: 280px">
                <template slot="append">元</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="收费类型" prop="projectPaymentTypeId">
              <el-select v-model="form.projectPaymentTypeId" @change="selectProjectPaymentType" clearable placeholder="请选择" style="width: 280px">
                <el-option
                  v-for="item in projectPaymentTypeList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
            <el-col :span="12">
              <el-form-item label="下浮率" prop="projectBudget">
                <el-input v-model="form.projectFloatPercentage" placeholder="请输入下浮率" style="width: 280px">
                  <template slot="append">%（百分比）</template>
                </el-input>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="项目服务费预计收入" prop="projectRxpectedIncome">
                <el-input v-model="form.projectRxpectedIncome" placeholder="请输入项目预期收入" style="width: 280px">
                  <template slot="append">元</template>

                  <el-button slot="append" @click="getFeeCalculator" type="success" icon="el-icon-search">自动计算</el-button>
                </el-input>
              </el-form-item>
            </el-col>
        </el-row>

        <el-row>
            <el-col :span="12">
              <el-form-item label="标书单价" prop="bidUnitPrice">
                <el-input v-model="form.bidUnitPrice" placeholder="请输入标书单价" style="width: 280px">
                  <template slot="append">元</template>
                </el-input>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="实收服务费" prop="paidServiceFee">
                <el-input v-model="form.paidServiceFee" placeholder="请输入实收服务费" style="width: 280px">
                  <template slot="append">元</template>
                </el-input>
              </el-form-item>
            </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="委托业主" prop="projectTenderee">
              <el-input :disabled="true" v-model="form.projectTenderee" placeholder="请选择招标人" style="width: 280px">
                <el-button slot="append" @click="showProjectTenderee" type="success" icon="el-icon-search">选择</el-button>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="资质主体" prop="projectAgencyId">
              <el-select v-model="form.projectAgencyId" @change="selectProjectAgency" clearable placeholder="请选择" style="width: 280px">
                <el-option
                  v-for="item in projectagencyList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="业主联系人" prop="projectTendereeContactPerson">
              <el-input v-model="form.projectTendereeContactPerson" placeholder="请输入业主联系人" style="width: 280px"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="业主联系方式" prop="projectTendereeContactTel">
              <el-input v-model="form.projectTendereeContactTel" placeholder="请输入业主联系方式" style="width: 280px"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="业主联系地址" prop="projectTendereeContactAddr">
                <el-input v-model="form.projectTendereeContactAddr" placeholder="请输入业主联系地址" style="width: 280px"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="开标地址" prop="projectBidOpenAddr">
              <el-input v-model="form.projectBidOpenAddr" placeholder="请输入评标地址" style="width: 280px"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="项目开发人员" prop="projectDeveloper">
              <el-input :disabled="true" v-model="form.projectDeveloper" placeholder="请输入项目开发人员" style="width: 280px" >
                <el-button slot="append" @click="showProjectDeveloper" icon="el-icon-search">选择</el-button>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目执行人" prop="projectOperator">
              <el-input :disabled="true" v-model="form.projectOperator" placeholder="请选择项目执行人" style="width: 280px" >
                <el-button slot="append" @click="showProjectOperator" icon="el-icon-search">选择</el-button>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="项目所属部门" prop="projectDeptId">
              <treeselect @select="selectProjectDept" v-model="form.projectDeptId" :options="deptList" :show-count="true" placeholder="请选择归属部门" style="width: 280px"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目负责人" prop="projectLeader">
              <el-input :disabled="true" v-model="form.projectLeader" placeholder="请选择项目负责人" style="width: 280px">
                <el-button slot="append" @click="showProjectLeader" icon="el-icon-search">选择</el-button>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="项目执行地区" prop="projectAreaId">
              <el-select v-model="form.projectAreaId" @change="selectProjectArea" clearable placeholder="请选择" style="width: 280px">
                <el-option
                  v-for="item in companyAreaList"
                  :key="item.areaId"
                  :label="item.areaName"
                  :value="item.areaId">

                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="开标时间" prop="projectBidOpenTime">
              <el-date-picker clearable
                v-model="form.projectBidOpenTime"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="请选择开标时间"
                style="width: 280px">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>


        <el-row>
          <el-col :span="12">
            <el-form-item label="中标单位" prop="projectWinBidderId">
              <el-select v-model="form.projectWinBidderId" @change="selectProjectWinBidder" clearable placeholder="请选择" style="width: 280px">
                <el-option
                  v-for="item in bidderList"
                  :key="item.id"
                  :label="item.companyName"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="12">
              <el-form-item label="评标时间" prop="projectBidMakeTime">
                <el-date-picker clearable
                  v-model="form.projectBidMakeTime"
                  type="datetime"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  placeholder="请选择评标时间"
                  style="width: 280px">
                </el-date-picker>
              </el-form-item>
            </el-col>
        </el-row>

        <el-row>
          <el-form-item label="项目说明" prop="projectDescription">
            <el-input v-model="form.projectDescription" type="textarea" placeholder="请输入内容" :rows="4" style="width: 760px"/>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="项目备注" prop="projectRemark">
            <el-input v-model="form.projectRemark" type="textarea" placeholder="请输入项目备注" :rows="4" style="width: 760px"/>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="项目附件" prop="attachmentSrc">
            <file-upload v-model="form.attachmentSrc"/>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="公告附件" prop="noticeFile">
            <file-upload v-model="form.noticeFile"/>
          </el-form-item>
        </el-row>
        <el-form-item label="排序" prop="sort">
          <el-input v-model="form.sort" placeholder="请输入排序" style="width: 280px"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


    <el-dialog title="导入项目" :visible.sync="openImport" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="openImport = false">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { listProject, getProject, delProject, addProject, updateProject,getProjectAgentfee } from "@/api/system/project";
import { deptTreeSelect } from "@/api/system/user";
import { listsBidder } from "@/api/system/bidder";
import { listsProjectpayer } from "@/api/system/projectpayer";
import { listsProjectbidevaluationprocess } from "@/api/system/projectbidevaluationprocess";
import { listsProjecttendermode } from "@/api/system/projecttendermode";
import { listsProjecttype } from "@/api/system/projecttype";
import { listsProjectbidevaluationmode } from "@/api/system/projectbidevaluationmode";
import { listsProjectfundingsource } from "@/api/system/projectfundingsource";
import { listsCompany } from "@/api/system/company";
import { listsCompanyarea } from "@/api/system/companyarea";

import Treeselect from "@riophae/vue-treeselect";
import Tenderer from "@/components/Tenderer";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import User from "@/components/User";
import { getToken } from "@/utils/auth";

export default {
  name: "Project",
  components: {User, Treeselect,Tenderer },
  data() {
    return {
      // 遮罩层
      formInnerVisible:false,
      formInnerType:null,
      formInnerTitle:null,
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 项目管理表格数据
      projectList: [],
      // 招标类型
      projecttypeList: [],
      // 招标方式
      projecttendermodeList: [],
      // 服务费付款方
      projectpayerList: [],
      // 资金来源
      projectfundingsourceList: [],
      // 项目流程
      projectbidevaluationprocessList: [],
      // 评标方法
      projectbidevaluationmodeList: [],
      // 资质主体
      projectagencyList: [],
      // 部门列表
      deptList: [],
      //列表
      companyAreaList:[],
      // 投标单位列表
      bidderList: [],
      // 立项日期范围
      createDateRange: [],

      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      openImport: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectName: null,
        projectCode: null,
        projectExternaltCode: null,
        projectTypeId: null,
        projectTypeName: null,
        projectTenderModeId: null,
        projectTenderModeName: null,
        projectBudget: null,
        projectRxpectedIncome: null,
        projectTendererId: null,
        projectTendererName: null,
        projectLeaderId: null,
        projectLeader: null,
        projectOperatorId: null,
        projectOperator: null,
        projectImplementAreaId: null,
        projectImplementArea: null,
        projectDeptId: null,
        projectDeptName: null,
        projectAreaId: null,
        projectAreaName: null,
        projectAgencyId: null,
        projectAgencyName: null,
        approvalStatus: null,
        projectStatus: null,
        projectBidevaluationModeId: null,
        projectBidevaluationModeName: null,
        projectBidevaluationProcessId: null,
        projectBidevaluationProcessName: null,
        projectFundingSourceId: null,
        projectFundingSourceName: null,
        projectPayerId: null,
        projectPayerName: null,
        projectDeveloperId: null,
        projectDeveloper: null,
        projectDescription: null,
        projectRemark: null,
        attachmentSrc: null,
        projectTendereeId: null,
        projectTenderee: null,
        projectTendereeContactPerson: null,
        projectTendereeContactTel: null,
        sort: null,
      },
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/system/project/importData"
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      projectCodeSelectList:[
        {value:1,label:"自行编号"},
        {value:2,label:"系统分配编号"},
      ],
      projectPaymentTypeList:[
        {value:1,label:"标准[差额定率累进法]"},
        {value:2,label:"定额"},
      ]
    };
  },
  created() {
    this.getList();
    this.getProjecttypeList();
    this.getProjecttendermodeList();
    this.getProjectpayerList();
    this.getProjectfundingsourceList();
    this.getProjectbidevaluationprocessList();
    this.getProjectbidevaluationmodeList();
    this.getListsCompany();
    this.getCompanyAreaList();
    this.getDeptTree();
    this.getBidderList();
  },
  methods: {
    /** 查询项目管理列表 */
    getList() {
      this.loading = true;
      listProject(this.queryParams).then(response => {
        this.projectList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        projectName: null,
        isProjectCode:2,
        projectCode: null,
        projectExternaltCode: null,
        projectTypeId: null,
        projectTypeName: null,
        projectTenderModeId: null,
        projectTenderModeName: null,
        projectBudget: null,
        projectRxpectedIncome: null,
        projectTendererId: null,
        projectTendererName: null,
        projectLeaderId: null,
        projectLeader: null,
        projectOperatorId: null,
        projectOperator: null,
        projectImplementAreaId: null,
        projectImplementArea: null,
        projectDeptId: null,
        projectDeptName: null,
        projectAreaId: null,
        projectAreaName: null,
        projectAgencyId: null,
        projectAgencyName: null,
        approvalStatus: null,
        projectStatus: null,
        projectBidevaluationModeId: null,
        projectBidevaluationModeName: null,
        projectBidevaluationProcessId: null,
        projectBidevaluationProcessName: null,
        projectFundingSourceId: null,
        projectFundingSourceName: null,
        projectPayerId: null,
        projectPayerName: null,
        projectDeveloperId: null,
        projectDeveloper: null,
        projectDescription: null,
        projectRemark: null,
        attachmentSrc: null,
        noticeFile: null,
        projectTendereeId: null,
        projectTenderee: null,
        projectTendereeContactPerson: null,
        projectTendereeContactTel: null,
        sort: null,
        bidUnitPrice: null,
        paidServiceFee: null,
        projectPaymentTypeId:null,
        projectPaymentTypeName:null,
        projectFloatPercentage:null,
        projectBidOpenTime:null,
        projectBidOpenAddr:null,
        createTime: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.queryParams = this.addDateRange(this.queryParams, this.createDateRange,'CreateTime')
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加项目管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getProject(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改项目管理";
      });
    },
    /** 打开导入表弹窗 */
    openImportTable() {
      this.openImport = true;
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateProject(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addProject(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除项目管理编号为"' + ids + '"的数据项？').then(function() {
        return delProject(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/project/export', {
        ...this.queryParams
      }, `project_${new Date().getTime()}.xlsx`)
    },
    getBidderList() {
      this.loading = true;
      listsBidder(this.queryParams).then(response => {
        this.bidderList = response.data;
        this.loading = false;
      });
    },
    getProjecttypeList() {
      this.loading = true;
      listsProjecttype(this.queryParams).then(response => {
        this.projecttypeList = response.data;
        this.loading = false;
      });
    },
    getProjecttendermodeList() {
      this.loading = true;
      listsProjecttendermode(this.queryParams).then(response => {
        this.projecttendermodeList = response.data;
        this.loading = false;
      });
    },
    getProjectpayerList() {
      this.loading = true;
      listsProjectpayer(this.queryParams).then(response => {
        this.projectpayerList = response.data;
        this.loading = false;
      });
    },
    getProjectfundingsourceList() {
      this.loading = true;
      listsProjectfundingsource(this.queryParams).then(response => {
        this.projectfundingsourceList = response.data;
        this.loading = false;
      });
    },
    getProjectbidevaluationprocessList() {
      this.loading = true;
      listsProjectbidevaluationprocess(this.queryParams).then(response => {
        this.projectbidevaluationprocessList = response.data;
        this.loading = false;
      });
    },
    getProjectbidevaluationmodeList() {
      this.loading = true;
      listsProjectbidevaluationmode(this.queryParams).then(response => {
        this.projectbidevaluationmodeList = response.data;
        this.loading = false;
      });
    },
    getListsCompany() {
      this.loading = true;
      listsCompany(this.queryParams).then(response => {
        this.projectagencyList = response.data;
        this.loading = false;
      });
    },
    /** 查询部门下拉树结构 */
    getDeptTree() {
      deptTreeSelect().then(response => {
        this.deptList = response.data;
      });
    },
    getCompanyAreaList() {
      this.loading = true;
      listsCompanyarea(this.queryParams).then(response => {
        this.companyAreaList = response.data;
        this.loading = false;
      });
    },
    selectProjectType(value) {
      // 通过已选的value值找到对应的对象
      const selectedOption = this.projecttypeList.find(option => option.id === value);
      if (selectedOption) {
        this.form.projectTypeName = selectedOption.text;
      }
    },
    selectProjectTenderMode(value) {
      // 通过已选的value值找到对应的对象
      const selectedOption = this.projecttendermodeList.find(option => option.id === value);
      if (selectedOption) {
        this.form.projectTenderModeName = selectedOption.name;
      }
    },
    selectProjectBidevaluationProcess(value) {
      // 通过已选的value值找到对应的对象
      const selectedOption = this.projectbidevaluationprocessList.find(option => option.id === value);
      if (selectedOption) {
        this.form.projectBidevaluationProcessName = selectedOption.text;
      }
    },
    selectProjectBidevaluationMode(value) {
      // 通过已选的value值找到对应的对象
      const selectedOption = this.projectbidevaluationmodeList.find(option => option.id === value);

      if (selectedOption) {
        this.form.projectBidevaluationModeName = selectedOption.text;
      }
    },
    selectProjectFundingSource(value) {
      // 通过已选的value值找到对应的对象
      const selectedOption = this.projectfundingsourceList.find(option => option.id === value);
      if (selectedOption) {
        this.form.projectFundingSourceName = selectedOption.text;
      }
    },
    selectProjectPayer(value) {
      // 通过已选的value值找到对应的对象
      const selectedOption = this.projectpayerList.find(option => option.id === value);
      if (selectedOption) {
        this.form.projectPayerName = selectedOption.name;
      }
    },
    selectProjectAgency(value) {
      // 通过已选的value值找到对应的对象
      const selectedOption = this.projectagencyList.find(option => option.id === value);
      if (selectedOption) {
        this.form.projectAgencyName = selectedOption.name;
      }
    },
    selectProjectArea(value) {
      // 通过已选的value值找到对应的对象
      const selectedOption = this.companyAreaList.find(option => option.areaId === value);
      if (selectedOption) {
        this.form.projectAreaName = selectedOption.areaName;
      }
    },
    selectProjectDept(value) {
      this.form.projectDeptName = value.label;
    },
    selectProjectPaymentType(value){
      const selectedOption = this.projectPaymentTypeList.find(option => option.value === value);
      if (selectedOption) {
        this.form.projectPaymentTypeName = selectedOption.label;
      }
    },
    selectProjectWinBidder(value){
      const selectedOption = this.bidderList.find(option => option.id === value);
      console.log(selectedOption)
      if (selectedOption) {
        this.form.projectWinBidder = selectedOption.companyName;
      }
    },
    showProjectTenderee(){
      this.formInnerVisible = true;
      this.formInnerTitle = "选择委托业主";
      this.formInnerType = "projectTenderee";
    },
    showProjectDeveloper(){
      this.formInnerVisible = true;
      this.formInnerTitle = "选择项目开发人员";
      this.formInnerType = "projectDeveloper";
    },
    showProjectOperator(){
      this.formInnerVisible = true;
      this.formInnerTitle = "选择项目执行人";
      this.formInnerType = "projectOperator";
    },
    showProjectLeader(){
      this.formInnerVisible = true;
      this.formInnerTitle = "选择项目负责人";
      this.formInnerType = "projectLeader";
    },
    getProjectTendereeRow(row){
      this.form.projectTendereeId =row.id;
      this.form.projectTenderee =row.tendererName;
      this.formInnerVisible = false;
    },
    getProjectDeveloperRow(row){
      this.form.projectDeveloperId =row.userId;
      this.form.projectDeveloper =row.nickName;
      this.formInnerVisible = false;
    },
    getProjectOperatorRow(row){
      this.form.projectOperatorId =row.userId;
      this.form.projectOperator =row.nickName;
      this.formInnerVisible = false;
    },
    getProjectLeaderRow(row){
      this.form.projectLeaderId =row.userId;
      this.form.projectLeader =row.nickName;
      this.formInnerVisible = false;
    },
    /** 下载模板操作 */
    importTemplate() {
      /*
      this.download('system/project/importTemplate', {
      }, `user_template_${new Date().getTime()}.xlsx`)
      */

      let a = document.createElement("a");
        a.href = "/static/excel/project_template.xlsx";
        a.download = "项目模板.xlsx";
        a.style.display = "none";
        document.body.appendChild(a);
        a.click();
        a.remove();
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },
    // 计算
    getFeeCalculator(){
      // form.projectBudget 预算
      //this.form.projectPaymentTypeId

      //this.this.form.projectPaymentTypeName

      //this.form.projectFloatPercentage 下浮
      if(this.form.projectTypeName == null){
        this.$message.error('请选择招标类型');
        return;
      }

      if(this.form.projectBudget == null || this.form.projectBudget < 0){
        this.$message.error('请输入项目预算');
        return;
      }

      if(this.form.projectPaymentTypeName == "定额"){
        this.$message.error('收费类型为定额收取不需要计算');
        return;
      }

      let form = {};
      form.name = this.form.projectTypeName;
      form.amount = this.form.projectBudget;
      form.projectPaymentTypeName = this.form.projectPaymentTypeName;
      form.downRate = this.form.projectFloatPercentage;
      this.loading = true;
      getProjectAgentfee(form).then(response => {
        console.log(response.data)
        this.form.projectRxpectedIncome = response.data.fee;
        this.loading = false;
      });

    }
  }
};
</script>
